package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sky.po.SetmealDishPO;
import com.sky.repository.SetmealDishRepository;
import com.sky.service.SetmealDishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 套餐业务实现
 */
@Service
@Slf4j
public class SetmealDishServiceImpl extends ServiceImpl<SetmealDishRepository,SetmealDishPO> implements SetmealDishService {

    @Autowired
    private SetmealDishRepository setmealDishRepository;

    @Transactional
    @Override
    public void insertBatch(List<SetmealDishPO> source) {
//        this.insertBatch(source);
        this.saveBatch(source);
    }

    @Override
    public void deleteBatchBySetmealId(List<Long> ids) {
        baseMapper.delete(new LambdaQueryWrapper<SetmealDishPO>()
                .in(SetmealDishPO::getSetmealId,ids));
    }

    /**
     * 根据套餐id查询套餐与菜品关系数据
     * @param id
     * @return
     */
    @Override
    public List<SetmealDishPO> selectBySetmealId(Long id) {
        return setmealDishRepository.selectList(new LambdaQueryWrapper<SetmealDishPO>()
                .eq(SetmealDishPO::getSetmealId,id));
    }
}
